package com.guandeng.mall.controller;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.guandeng.mall.services.MemberService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping
public class HelloController {

    @Resource
    private MemberService memberService;

    @PostMapping("/service")
    public String service(@RequestParam(value = "user") String username) {
        System.out.println(username);
        String hello = memberService.sayHello();
        return hello;
//        return CommonResult.success(hello);
    }

    @PostMapping("/snowflake")
    public Long snowflake() {
        //参数1为终端ID
//参数2为数据中心ID
        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
        long id = snowflake.nextId();

//简单使用
//        long id = IdUtil.getSnowflakeNextId();
//        String id = snowflake.getSnowflakeNextIdStr();
        return id;
//        return CommonResult.success("test");
    }

}

